package com.hgt.springcloud.service.impl;

import com.hgt.springcloud.service.IMessageProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;

/**
 * @author HuangGaoTao 929507053@qq.com
 * @Created: 2021/7/1 15:34
 */
@EnableBinding(Source.class) //定义消息的推送管道
@Slf4j
public class MessageProviderImpl implements IMessageProvider {

    @Autowired
    private MessageChannel output; //消息发送管道

    @Override
    public String send() {

        //简单实现   发送一个流水号
        String s = UUID.randomUUID().toString();
        //将这个流水号 发送到消息中间件中
        output.send(MessageBuilder.withPayload(s).build());
        log.info("*****************serial:"+s);
        return null;
    }
}
